{extend name=".././view/list.html" /}
{block name="jsset"}
{/block}
{block name="nav"}
<span class="layui-breadcrumb">
	<a href="">考试管理</a>
	<a><cite>考试列表</cite></a>
</span>
{/block}
{block name="search"}
<div class="layui-form-item">
	<label for="searchval" class="layui-form-label">
		关键字
	</label>
	<div class="layui-input-block">
		<input type="text" id="searchval" name="searchval" autocomplete="off" class="layui-input">
	</div>
</div>
<div class="layui-form-item">
	<label for="xueqi_id" class="layui-form-label" class="layui-input">学期</label>
	<div class="layui-input-block">
		<select name="xueqi_id" id="xueqi_id">
		</select>
	</div>
</div>
<div class="layui-form-item">
	<label for="category_id" class="layui-form-label">考试类型</label>
	<div class="layui-input-block">
		<select name="category_id" id="category_id">
		</select>
	</div>
</div>
<div class="layui-form-item" style="text-align: right;">
	<button class="layui-btn" lay-filter="searchSubmit" lay-submit="">搜索</button>
</div>
{/block}
{block name="table"}
<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-danger" lay-event="dels">
			<i class="iconfont">&#xe69d;</i> 批量删除
		</button>
		<button class="layui-btn" lay-event="addxd">
			<i class="iconfont">&#xe6b9;</i> 新建考试向导
		</button>
		<button class="layui-btn" lay-event="add">
			<i class="iconfont">&#xe6b9;</i> 新建
		</button>
	</div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></a>
	<a class="layui-btn-xs" lay-event="fenshuxian" title="分数线"><i class="layui-icon layui-icon-slider"></i></a>
	<a class="layui-btn-xs" lay-event="kaohao" title="生成考号"><i class="layui-icon layui-icon-user"></i></a>
	<a class="layui-btn-xs" lay-event="lurufengong" title="录入分工"><i class="layui-icon layui-icon-senior"></i></a>
	<a class="layui-btn-xs" lay-event="tongji" title="统计"><i class="layui-icon layui-icon-chart"></i></a>
	<a class="layui-btn-xs" lay-event="chengji" title="查看成绩"><i class="layui-icon layui-icon-website"></i></a>
<!-- 	<a class="layui-btn-xs" lay-event="renke" title="任课教师"><i class="layui-icon layui-icon-friends"></i></a>
 -->	<a class="layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon">&#xe640;</i></a>
</script>
<script type="text/html" id="luru">
	<input type="checkbox" myurl="{$list.luru ? $list.luru : url('luru')}" {{d.luru == 1 ? "checked" :""}} id="{{d.id}}" lay-skin="switch" lay-filter="luru" lay-text="允许|不允许">
</script>
<script type="text/html" id="jieshu">
	<input type="checkbox" myurl="{$list.status ? $list.status : url('status')}" {{d.status == 1 ? "checked" :""}} id="{{d.id}}" lay-skin="switch" lay-filter="status" lay-text="进行|结束">
</script>
<!-- 表格操作 -->
<script>
// 提交搜索条件后重载表格
layui.use(['table', 'mytable','createInput','form'], function() {
	var table = layui.table,
		mytable = layui.mytable,
		form = layui.form,
		cInput = layui.createInput;

	cInput.categorySelect('xueqi_id', 108);
	cInput.categorySelect('category_id', 109);

	// 设置列
	options.cols = [
		[ //表头
			{ type: 'checkbox', fixed: 'left' },
			{ field: 'title', title: '考试名称', sort: true, minWidth: 240, fixed: 'left' },
			{
				field: 'xueqi_id',
				title: '学期',
				sort: true,
				minWidth: 200,
				templet: function(d) {
					var str;
					if (d.ksXueqi) {
						str = d.ksXueqi.title;
					}
					return str;
				}
			},
			{ field: "ckNianji", title: '参考年级', minWidth: 180 },
			{ field: 'ckSubject', title: '参考学科', minWidth: 100 },
			{
				field: 'bfdate',
				title: '考试时间',
				minWidth: 150,
				sort: true,
				templet: function(d) {
					var date;
					date = d.enddate.split('-');

					endate = date[1] + '-' + date[2];
					endate = d.bfdate + '～' + endate;
					return endate;
				}
			},
			{
				field: 'user_id',
				title: '创建人',
				sort: true,
				minWidth: 100,
				templet: function(d) {
					var str;
					if (d.ksTeahcer) {
						str = d.ksTeahcer.xingming;
					}
					return str;
				}
			},
			{ field: 'luru', title: '成绩编辑', minWidth: 100, templet: '#luru', sort: true },
			{ field: 'status', title: '状态', minWidth: 80, templet: '#jieshu', sort: true },
			{ field: 'id', title: '操作', toolbar: '#barDemo', minWidth: 250 },
		]
	];

	// 获取筛选条件并加载表格
	options.where = form.val("search");
	userTable = table.render(options); //获取数据并渲染

	//表头工具栏事件
	table.on('toolbar(mytable)', function(obj) {
		switch (obj.event) {
			case 'dels':
				var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
				mytable.delAll(checkStatus, '/kaoshi/index/delete', 'mytable');
				break;
			case 'add':
				xadmin.open('新建考试', '/kaoshi/index/create', '600', '400', false);
				break;
			case 'addxd':
				xadmin.open('创建考试向导', '/kaoshi/index/setp1', '', '', true);
				break;
		};
	});

	//监听行工具条
	table.on('tool(mytable)', function(obj) {
		var data = obj.data; //获得当前行数据
		var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		var tr = obj.tr; //获得当前行 tr 的DOM对象
		switch (layEvent) {
			case 'del': // 删除
				mytable.del(obj, '/kaoshi/index/delete');
				break;
			case 'edit': // 编辑
				xadmin.open('编辑考试', '/kaoshi/index/edit/' + obj.data.id, '600', '400', false);
				break;
			case 'tongji': // 状态
				xadmin.open(obj.data.title + ' 成绩统计', '/kaoshi/index/tongji/' + obj.data.id, '650', '400', false);
				break;
			case 'fenshuxian': // 设置分数线
				parent.xadmin.add_tab(obj.data.title + ' 分数线', '/kaoshi/kaoshiset/index/' + obj.data.id, true);
				break;
			case 'kaohao': // 生成考号
				xadmin.open(obj.data.title + ' 生成考号', '/kaohao/index/createall/' + obj.data.id, '550', '300', false);
				break;
			case 'chengji': // 查询成绩
				parent.xadmin.add_tab(obj.data.title + ' 查看成绩', '/kaoshi/index/chengji/' + obj.data.id, true);
				break;
			case 'renke': // 查询成绩
				parent.xadmin.add_tab(obj.data.title + ' 任课教师设置', '/chengji/bjtj/renke/' + obj.data.id, true);
				break;
			case 'lurufengong': // 查询成绩
				parent.xadmin.add_tab(obj.data.title + ' 录入成绩分工', '/kaoshi/lrfg/index/' + obj.data.id, true);
				break;
		};
	});
});

</script>
{/block}
